﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SMTC.Model.Model;
using System.Web.UI;
using System.Globalization;
using System.Threading;
using System.Web;

namespace SMTC.WebCommon.Common
{
    public class BasePage : System.Web.UI.Page
    {
        public string UserID
        { 
            get
            {
                if (Session["STMCUser"] != null)
                {
                    return ((SMT_UserInfo)Session["STMCUser"]).UserID;
                }
                else
                {
                    Response.Redirect(@"~/UserPower/UserLogin.aspx");
                    throw new Exception("Please login again！");
                }
            }
        }

        public string UserName
        {
            get
            {
                if (Session["STMCUser"] != null)
                {
                    return ((SMT_UserInfo)Session["STMCUser"]).UserName;
                }
                else
                {
                    Response.Redirect(@"~/UserPower/UserLogin.aspx");
                    throw new Exception("Please login again！");
                }
            }
        }
        public void ShowMessage(string msg)
        {
            ClientScriptManager cs = ClientScript;
            cs.RegisterStartupScript(GetType(), "ShowMsg", string.Format("showMessage('{0}');", msg), true);
        }

        protected override void InitializeCulture()
        {
            if (HttpContext.Current.Session["languagetype"] != null)
            {
                string language = HttpContext.Current.Session["languagetype"].ToString();

                if (!String.IsNullOrEmpty(language))
                {
                    Thread.CurrentThread.CurrentUICulture = new CultureInfo(language);
                    Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(language);
                }

            }
            base.InitializeCulture();
        }
    }
}
